<?php
/**
 * 涂医生管理
 * 
 * @author  Lee<a605333742@gmail.com>
 * @time    2016-07-30
 */
namespace Admin\Controller;

class DoctorController extends CommonController{
    /*
     * 构造函数
     * 
     * @return  #
     */
    public function _initialize() {
        parent::_initialize();
        $this->db       =new \Model\DoctorModel();
        $this->db_doc   =new \Model\DoctorquesttypeModel();
        $this->db_com   =new \Model\CommentModel();
    }
    
    /*
     * 涂医生论坛正常发表文章列表
     * 
     * @return #
     */
    public function index(){
        $map['state']   =2;
        if(session('type')<2){
            $map['userId']  =session("authId");
        }
        $sortBy         ='top';
        $sotr           =desc;
        $docList        =$this->_list($this->db,$map,$sortBy,$sotr);
        $this->assign("docList",$docList);
        $this->assign('act',1);       
        $this->display();
    }
    
    /*
     * 涂医生论坛待审列表
     * 
     * @return #
     */
    public function auditDocInfo(){
        $map['state']   =1;
        if(session('type')<2){
            $map['userId']  =session("authId");
        }
        $sortBy ='top';
        $sort   =desc;
        $docList=$this->_list($this->db,$map,$sortBy,$sort);
        $this->assign("docList",$docList);
        $this->assign("act",2);
        $this->display("index");
    }
    
    /*
     * 审核、批量审核帖子
     * 
     * @return bool
     */
    public function alledit(){       
        $map['id']      =I("request.id");
        $map['state']   =2;
        if($this->db->edits($map)){            
            $this->success("审核成功",U("index"));
        }else{
            $this->error("审核失败",U("index"));
        }
    }
    
    /*
     * 待审核，批量待审核
     * 
     * @return #
     */
    public function audit(){
        $map['id']      =I("request.id");
        $map['state']   =1;
        if($this->db->edits($map)){            
            $this->success("待审核成功",U("index"));
        }else{
            $this->error("待审核失败",U("index"));
        }
    }
    
    /*
     * 删除，批量删除帖子
     * 
     * @return #
     */
    public function del(){
        $map['id']      =I("request.id");
        $map['state']   =3;
        if($this->db->edits($map)){            
            $this->success("删除成功",U("index"));
        }else{
            $this->error("删除失败",U("index"));
        }
    }
    
    /*
     * 涂医生分类列表
     * 
     * @return #
     */
    public function docQuestTypeList(){
        $map    =$this->_search("Doctorquesttype");
        $docType=$this->_list($this->db_doc,$map);
        $this->assign("docTye",$docType);
        $this->display();
    }
    
    /*
     * 显示涂医生分类编辑
     * 
     * @return #
     */
    public function show(){
        if(I("request.id")){
           $docTypeInfo =$this->db_doc->find(I("request.id","","int"));
           $this->assign("docTypeInfo",$docTypeInfo);
        }
        $this->display();
    }
    
    /*
     * 编辑涂医生帖子分类
     * 
     * @return #
     */
    public function edit(){
        if(I('request.id')){
            $map['id']  =I("request.id","","int");
        }
        if(I("request.name")){
            $map['name']    =I("request.name","","trim");
        }else{
            $this->error("分类名称不能为空");
        }
        if($this->db_doc->edit($map)){
            $this->success("编辑成功");
        }else{
            $this->error("编辑失败");
        }
    }
    
    /*
     * 删除、批量删除涂医生分类列表
     * 
     * @return #
     */
    public function delType(){
        $map['id']  =I("request.id");
        if($this->db_doc->del($map)){
            $this->success("涂医生分类删除成功");
        }else{
            $this->error("涂医生分类删除失败");
        }
    }
    
    /*
     * 涂医生论坛正常回复表
     * 
     * @return #
     */
    public function comment(){
        $map['isUsed']  =1;
        $sortBy         ='top';
        $sort           =desc;
        $commentList    =$this->_list($this->db_com,$map,$sortBy,$sort);
        $this->assign("com",$commentList);
        $this->assign("act",1);
        $this->display();
    }
    
    /*
     * 待审核的帖子回复
     * @return  #
     */
    public function auditComment(){
        $map['isUsed']      =0;
        $sortBy             ='top';
        $sort               =desc;
        $auditCommentList   =$this->_list($this->db_com,$map,$sortBy,$sort);
        $this->assign("com",$auditCommentList);
        $this->assign('act',2);
        $this->display("comment");
    }
    
    /*审核，批量审核的帖子回复
     * 
     * @return #
     */
     public function alleditCom(){       
        $map['id']      =I("request.id");
        $map['isUsed']  =1;
        if($this->db_com->edits($map)){            
            $this->success("审核成功",U("index"));
        }else{
            $this->error("审核失败",U("index"));
        }
    }
    
    /*
     * 待审核，批量待审核帖子回复
     * 
     * @return #
     */
    public function auditCom(){
        $map['id']      =I("request.id");
        $map['isUsed']  =0;
        if($this->db_com->edits($map)){            
            $this->success("待审核成功",U("index"));
        }else{
            $this->error("待审核失败",U("index"));
        }
    }
    
    /*
     * 删除，批量删除帖子回复
     * 
     * @return #
     */
    public function delCom(){
        $map['id']      =I("request.id");
        $map['isUsed']  =3;
        if($this->db_com->edits($map)){            
            $this->success("删除成功",U("index"));
        }else{
            $this->error("删除失败",U("index"));
        }
    }
}
